<%--
  Created by IntelliJ IDEA.
  User: 71027
  Date: 2019/4/28
  Time: 14:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册页面</title>
    <%@include file="common/common.jsp" %>
    <%--记住这个样子？？？--%>
</head>
<body>
<h1 align="center">用户注册</h1>
<form class="">
    <div class="form-group"><label>用户名：</label><input type="text" name="userid"/><span id="useridspan"></span></div>
    <div class="form-group"><label>密码：</label><input type="text" name="password"/></div>
    <div class="form-group">
        <label>身份：</label>
        <input disabled="disabled" type="radio" name="identity" value="1"/>管理员
        <input type="radio" checked="checked" name="identity" value="2"/>用户
    </div>
</form>
<button onclick="register()">注册</button>
<a href="http://localhost:8080/Github_war_exploded/user/index">去登陆</a>
<div id="res"></div>
<script type="text/javascript">
    function register() {
        var res = false;
        var userid = $("input[name='userid']");
        var password = $("input[name='password']");
        if (userid.val() == "" || password.val() == "") {
            //检验
            var useridspan = document.getElementById("useridspan");
            useridspan.innerHTML = "不能为空。";
            useridspan.style.color = "red";
            return false;
        }

        var data = {};
        var arr = $('form').serializeArray();
        $.each(arr, function () {
            data [this.name] = this.value;
        });

        $.ajax({
            url: "http://localhost:8080/Github_war_exploded/user/registeraction",
            type: "GET",
            data: data,
            success: function (data) {
                var res = document.getElementById("res");
                res.innerHTML = "注册异常：该用户已经注册过！";
                res.style.color = "red";
            }, error: function (msg) {
                alert('ajax error');
                console.log(msg);
            }
        });
    }
</script>
</body>
</html>
